package gdconf

import (
	"server_cluster/common/logger"
)

// 每日签到配置表

type SignInConfig struct {
	Day      int32 `csv:"id" gorm:"primary_key;autoIncrement:false"` // 天数
	RewardId int32 `csv:"reward,omitempty"`                          // 奖励id
}

func (s *SignInConfig) TableName() string {
	return "config_sign_in"
}

func (g *GameDataConfig) saveSignInConfig() {
	saveTableToDb[SignInConfig](g.Db, readTable[SignInConfig](g.CsvPathPrefix+"SignIn.csv"))
}

func (g *GameDataConfig) loadSignInConfig() {
	g.GameDataMaps.SignInConfigMap = make(map[int32]*SignInConfig)
	for _, signInConfig := range loadTableFromDb[SignInConfig](g.Db) {
		g.GameDataMaps.SignInConfigMap[signInConfig.Day] = signInConfig
	}
	logger.Info("SignInConfig Count: %v", len(g.GameDataMaps.SignInConfigMap))
}

func GetSignInConfig(day int32) *SignInConfig {
	value, exist := CONF.GameDataMaps.SignInConfigMap[day]
	if !exist {
		logger.Error("[ConfigNotFound] SignInConfig, day: %v", day)
		return nil
	}
	return value
}

func GetSignInConfigMap() map[int32]*SignInConfig {
	return CONF.GameDataMaps.SignInConfigMap
}
